/*
    This source file is part of GeNa project.
    Copyright © GeNa project 2008
    For the latest info, see http://code.google.com/p/genaproject/ or  http://lumpyproject.forums-rpg.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef MODEL_H_INCLUDED
#define MODEL_H_INCLUDED

#include <string>
#include <map>

//Boost serialization
#include <boost/archive/basic_archive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/version.hpp>

using namespace boost::serialization;

#ifndef WX_PCH_H_INCLUDED
#include "wx_pch.h"
#endif

#include "map.h"
#include "map_manager.h"
#include "entity.h"
#include "math/vector.h"
#include "math/quaternion.h"
#include "object.h"

class ModelMesh;

class Model : public ObjectOf<Model>
{
public:
    Entity* entity;
    string name;

    bool isSelected;

    math::quaternionq orientation;
    math::vector3q     position;

    template<class Archive> void serialize(Archive & ar, const unsigned int version);

    Model()
    {
        entity = NULL;
        position = math::vector3q::Null;
        orientation = math::quaternionq::Identity;
        isSelected = false;
    }

    void convert( Object::Conv conv)
    {
    }

    void load(Map* map);
    void select();
    void unselect();

    void draw(bool noEffect = false);

    float getSqDistanceFromAxis(  math::vector3q p, math::vector3a v);
};

BOOST_CLASS_VERSION(Model, 0)

class ModelManager
{
private:
    std::map< std::string, Entity*> entityList;
public:
    ModelManager(Map* _map)
    {
        map = _map;
    }

    static ModelManager & getInstance()
    {
        return *(mapManagerInstance.current->modelManager);
    }

    Map* map;

    Entity* load( std::string name);

};


#endif // MODEL_H_INCLUDED
